package com.wooophone.buyi.dao.impl;

import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import com.wooophone.buyi.bean.User;
import com.wooophone.buyi.bean.WeiboUser;
import com.wooophone.buyi.dao.UserDao;

public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {

	public UserDaoImpl() {
		super(User.class);
	}

	@Override
	public User getByWeiboUser(WeiboUser weiboUser) {
		return isResult("weiboUserId", weiboUser.getId());
	}

	@Override
	public User getByUserName(String userName) {
		return isResult("userName",userName);
	}

	@Override
	public boolean existByUserName(String userName) {
		return mongoOperations.count(
				Query.query(Criteria.where("userName").is(userName)),
				entityClass) > 0;
	}

	@Override
	public boolean existByEmail(String email) {
		return mongoOperations.count(
				Query.query(Criteria.where("email").is(email)), entityClass) > 0;
	}

	@Override
	public User getByEmail(String email) {
		return isResult("email",email);
	}

	@Override
	public User getByWeiboUserId(String id) {
		return  isResult("weiboUserId", id);
	}

	public void setMongoOperations(MongoOperations mongoOperations) {
		super.mongoOperations=mongoOperations;
	}
}
